<?php

/** Zend_View_Helper_Abstract.php */
require_once 'Zend/View/Helper/Abstract.php';

class Project_View_Helper_Message extends Zend_View_Helper_Abstract
{
    /**
     * 显示消息
     *
     * @param string $content
     * @param string $url
     * @param float $time
     * @return string
     */
    public function message($content, $url = '', $time = 2)
    {//消息 单位秒
        if (empty($url)) {
            $url = @$_SERVER['HTTP_REFERER'];
        }
        
        if (preg_match("/^javascript:/i", $url)) {
            $javascriptString = str_replace("\"", "\\\"", $url);
            $javascriptString = preg_replace("/^javascript:/i", '', $javascriptString);
            $hrefString = str_replace("\"", "\\\"", $url);
        } else {
            $javascriptString = "location.href='{$url}';";
            $hrefString = $url; 
        }
        $millisecond = $time * 1000;
        $htmlString = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
            <html xmlns=\"http://www.w3.org/1999/xhtml\">
            <head>
            <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
            <title>系统提示消息</title>
            <script language=\"javascript\">setTimeout(\"{$javascriptString}\", {$millisecond});</script>
            </head>
            
            <body style=\"margin-top:200px;\">
                <div style=\"border:#9FACBE solid 1px; font-size:12px; margin:0 auto; width:500px;\">
                    <div style=\"line-height:24px; letter-spacing:1px; background-color:#9FACBE; color:#FFFFFF; letter-spacing: 2px;\">
                        <div style=\"padding-left:5px; font-weight:bold; \">系统提示</div>
                    </div>
                    <div style=\"line-height:30px; \">
                        <div style=\"padding-left:5px; margin-top:5px;\">{$content}</div>
                    </div>
                    <div>
                        <div style=\"padding-left:5px;padding-bottom:5px; \">
                            <a href=\"{$url}\" style=\"text-decoration:underline; color:#cccccc;\">如果你不想等待或者你的浏览器没有跳转，请点击这里。</a>
                        </div>
                    </div>
                </div>
            </body>
            </html>
        ";
        return $htmlString;
    }
}